package com.zhongchaowuye.controller;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.zhongchaowuye.pojo.B_HT;
import com.zhongchaowuye.service.B_HTService;

@Controller
@RequestMapping("/b_HT")
public class B_HTController {

	@Resource
	private B_HTService b_HTService;
	
	@RequestMapping(value ="/getB_HT",method = RequestMethod.POST)
	@ResponseBody
	//根据id获取B_HT对象信息
	public Map<String,Object> getB_HT(HttpServletRequest request,B_HT ht){
		Map<String,Object> m=new HashMap<>();
		Map<String,Object> reMap=new HashMap<>();
		try {
			B_HT b_HT=b_HTService.getB_HT(ht);
			reMap.put("b_HT", b_HT);
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", e.getMessage());
		}
		return reMap;
	}

	@RequestMapping(value ="/getB_HTList",method = RequestMethod.POST)
	@ResponseBody
	//获取列表
	public Map<String,Object> getB_HTList(HttpServletRequest request,B_HT b_HT){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			//List<Map<String,Object>> rList=b_HTService.getB_HTList(b_HT); //不带分页（注意实现类中的相应写法）
			Page<Map<String,Object>> rList = (Page)b_HTService.getB_HTList(b_HT);
			
			//System.out.println(rList);
			reMap.put("rows", rList);
			reMap.put("total", rList.getTotal());
			reMap.put("pageIndex", b_HT.getPageIndex());
			reMap.put("pageSize", b_HT.getPageSize());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", e.getMessage());
		}
		return reMap;
	}

	@RequestMapping(value ="/insertB_HT",method = RequestMethod.POST)
	@ResponseBody
	//添加
	public Map<String,Object> insertB_HT(HttpServletRequest request,B_HT b_HT)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			//补齐创建者与创建时间
			//b_HT.setCrea("");
			//Timestamp cur=new Timestamp(System.currentTimeMillis()); 
			//b_HT.setCrea_time(cur); //或者直接在sql语句中使用now()函数填充对应的值
			int flag=b_HTService.insertB_HT(b_HT);
			//int flag = 0;
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", e.getMessage());
		}
		return reMap;
	}
	
	@RequestMapping(value ="/updateB_HT",method = RequestMethod.POST)
	@ResponseBody
	//修改
	public Map<String,Object> updateB_HT(HttpServletRequest request,B_HT b_HT)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=b_HTService.updateB_HT(b_HT);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", e.getMessage());
		}
		return reMap;
	}
	
	@RequestMapping(value ="/delB_HT",method = RequestMethod.POST)
	@ResponseBody
	//软删除
	public Map<String,Object> delB_HT(HttpServletRequest request,B_HT b_HT)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		Map<String,Object> m=new HashMap<>();
		try 
		{
			int flag=b_HTService.delB_HT(b_HT);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", e.getMessage());
		}
		return reMap;
	}
}
